package com.ruoyi.project.wt.auditDaylogQuery.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.er.domain.PaeaErError;
import com.ruoyi.project.oms.paeaAuBatch.domain.PaeaAuBatch;
import com.ruoyi.project.stat.paeaReportBusiness.domain.PaeaReportBusiness;
import com.ruoyi.project.stat.paeaReportBusiness.mapper.PaeaReportBusinessMapper;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylogQuery;
import com.ruoyi.project.tool.DateTimeUtil;
import com.ruoyi.project.tool.export.HtmlToWord;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylog;
import com.ruoyi.project.wt.auditDaylogQuery.mapper.WtCheckDaylogMapper;
import com.ruoyi.project.wt.auditDaylogQuery.service.IWtCheckDaylogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.text.Convert;

/**
 * 监督日志Service业务层处理
 *
 * @author 魏刚
 * @date 2020-03-18
 */
@Service
public class WtCheckDaylogServiceImpl extends ServiceImpl<WtCheckDaylogMapper, WtCheckDaylog> implements IWtCheckDaylogService
{
    @Autowired
    private WtCheckDaylogMapper wtCheckDaylogMapper;
    @Autowired
    private PaeaReportBusinessMapper paeaReportBusinessMapper;
    /**
     * 查询监督日志
     *
     * @param id 监督日志ID
     * @return 监督日志
     */
    @Override
    public WtCheckDaylog selectWtCheckDaylogById(String id)
    {
        return wtCheckDaylogMapper.selectWtCheckDaylogById(id);
    }

    /**
     * 查询监督日志列表
     *
     * @param wtCheckDaylog 监督日志
     * @return 监督日志
     */
    @Override
    public List<WtCheckDaylog> selectWtCheckDaylogList(WtCheckDaylog wtCheckDaylog)
    {
        return wtCheckDaylogMapper.selectWtCheckDaylogList(wtCheckDaylog);
    }

    /**
     * 新增监督日志
     *
     * @param wtCheckDaylog 监督日志
     * @return 结果
     */
    @Override
    public int insertWtCheckDaylog(WtCheckDaylog wtCheckDaylog)
    {
        return wtCheckDaylogMapper.insertWtCheckDaylog(wtCheckDaylog);
    }

    /**
     * 修改监督日志
     *
     * @param wtCheckDaylog 监督日志
     * @return 结果
     */
    @Override
    public int updateWtCheckDaylog(WtCheckDaylog wtCheckDaylog)
    {
        return wtCheckDaylogMapper.updateWtCheckDaylog(wtCheckDaylog);
    }

    /**
     * 删除监督日志对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWtCheckDaylogByIds(String ids)
    {
        return wtCheckDaylogMapper.deleteWtCheckDaylogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除监督日志信息
     *
     * @param id 监督日志ID
     * @return 结果
     */
    @Override
    public int deleteWtCheckDaylogById(String id)
    {
        return wtCheckDaylogMapper.deleteWtCheckDaylogById(id);
    }

    //查询处理监督日志
    @Override
    public List<WtCheckDaylog> selectList(WtCheckDaylogQuery wtCheckDaylogQuery) {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        QueryWrapper queryWrapper = new QueryWrapper<>(wtCheckDaylog);
        /*if(StringUtils.isEmpty(wtCheckDaylogQuery.getCode())){
            ShiroUtils.getSysUser();
        }*/
        //日志编号
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getCode())){
            queryWrapper.eq("code",wtCheckDaylogQuery.getCode());
        }
        //日志日期
        if(wtCheckDaylogQuery.getBeginWorkDate()!=null&&wtCheckDaylogQuery.getEndWorkDate()!=null){
            queryWrapper.between("work_date",wtCheckDaylogQuery.getBeginWorkDate(),wtCheckDaylogQuery.getEndWorkDate());
        }else if(wtCheckDaylogQuery.getBeginWorkDate()!=null){
            queryWrapper.eq("work_date",wtCheckDaylogQuery.getBeginWorkDate());
        }
        //创建日期
        if(wtCheckDaylogQuery.getBeginCreateDate()!=null&&wtCheckDaylogQuery.getEndCreateDate()!=null){
            queryWrapper.between("create_date",wtCheckDaylogQuery.getBeginCreateDate(),wtCheckDaylogQuery.getEndCreateDate());
        }else if(wtCheckDaylogQuery.getBeginCreateDate()!=null){
            queryWrapper.eq("create_date",wtCheckDaylogQuery.getBeginWorkDate());
        }
        //监督员
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getCreateOper())){
            queryWrapper.eq("create_oper",wtCheckDaylogQuery.getCreateOper());
        }
        //机构
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getBrCode())){
            queryWrapper.eq("br_code",wtCheckDaylogQuery.getBrCode());
            //queryWrapper.exists("select id from sm_organ_query where sm_organ_query.org_code="+wtCheckDaylogQuery.getBrCode()+" and sm_organ_query.son_org_code=wt_check_daylog.br_code");
        }
        //状态
        if(wtCheckDaylogQuery.getAuditStatus()!=null){
            queryWrapper.eq("audit_status",wtCheckDaylogQuery.getAuditStatus());
        }
        queryWrapper.ne("state","0");
        List<WtCheckDaylog> list = wtCheckDaylogMapper.selectList(queryWrapper);
        return list;
    }
    //日常监督日志
    @Override
    public List<WtCheckDaylog> selectCreateList(WtCheckDaylogQuery wtCheckDaylogQuery) {
        WtCheckDaylog wtCheckDaylog = new WtCheckDaylog();
        QueryWrapper queryWrapper = new QueryWrapper<>(wtCheckDaylog);
        /*if(StringUtils.isEmpty(wtCheckDaylogQuery.getCode())){
            ShiroUtils.getSysUser();
        }*/
        //日志编号
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getCode())){
            queryWrapper.eq("code",wtCheckDaylogQuery.getCode());
        }
        //日志日期
        if(wtCheckDaylogQuery.getBeginWorkDate()!=null&&wtCheckDaylogQuery.getEndWorkDate()!=null){
            queryWrapper.between("work_date",wtCheckDaylogQuery.getBeginWorkDate(),wtCheckDaylogQuery.getEndWorkDate());
        }else if(wtCheckDaylogQuery.getBeginWorkDate()!=null){
            queryWrapper.eq("work_date",wtCheckDaylogQuery.getBeginWorkDate());
        }
        //创建日期
        if(wtCheckDaylogQuery.getBeginCreateDate()!=null&&wtCheckDaylogQuery.getEndCreateDate()!=null){
            queryWrapper.between("create_date",wtCheckDaylogQuery.getBeginCreateDate(),wtCheckDaylogQuery.getEndCreateDate());
        }else if(wtCheckDaylogQuery.getBeginCreateDate()!=null){
            queryWrapper.eq("create_date",wtCheckDaylogQuery.getBeginWorkDate());
        }
        //监督员
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getCreateOper())){
            queryWrapper.eq("create_oper",wtCheckDaylogQuery.getCreateOper());
        }else{
            User user = ShiroUtils.getSysUser();
            queryWrapper.eq("create_oper",user.getLoginName());
        }
        //机构
        if(StringUtils.isNotEmpty(wtCheckDaylogQuery.getBrCode())){
            queryWrapper.eq("br_code",wtCheckDaylogQuery.getBrCode());
            //queryWrapper.exists("select id from sm_organ_query where sm_organ_query.org_code="+wtCheckDaylogQuery.getBrCode()+" and sm_organ_query.son_org_code=wt_check_daylog.br_code");
        }
        //状态
        if(wtCheckDaylogQuery.getState()!=null){
            queryWrapper.eq("state",wtCheckDaylogQuery.getState());
        }
        List<WtCheckDaylog> list = wtCheckDaylogMapper.selectList(queryWrapper);
        return list;
    }
    @Override
    public int auditing(WtCheckDaylog wtCheckDaylog) {
        WtCheckDaylog dayLog = wtCheckDaylogMapper.selectById(wtCheckDaylog.getId());
        dayLog.setAuditStatus(1);
        dayLog.setWorkDesc2(wtCheckDaylog.getWorkDesc2());
        return wtCheckDaylogMapper.updateWtCheckDaylog(dayLog);

    }
    @Override
    public int auditingBack(WtCheckDaylog wtCheckDaylog) {
        WtCheckDaylog dayLog = wtCheckDaylogMapper.selectById(wtCheckDaylog.getId());
        dayLog.setState(new Integer(2));
        dayLog.setAuditStatus(new Integer(2));
        dayLog.setWorkDesc2(wtCheckDaylog.getWorkDesc2());
        return wtCheckDaylogMapper.updateWtCheckDaylog(dayLog);

    }
    @Override
    public int addUpdate(WtCheckDaylog wtCheckDaylog) {
        WtCheckDaylog dayLog = wtCheckDaylogMapper.selectById(wtCheckDaylog.getId());
        if(dayLog.getAuditStatus()==2){
            dayLog.setAuditStatus(new Integer(3));
        }
        dayLog.setState(new Integer(wtCheckDaylog.getState()));

        dayLog.setAuditNum(wtCheckDaylog.getAuditNum()); // 重点监控预警量
        dayLog.setArmsNum(wtCheckDaylog.getAuditNum()); // ARMS预警核销量
        dayLog.setOcrNum(wtCheckDaylog.getAuditNum()); // OCR督办量
        dayLog.setRestoreNum(wtCheckDaylog.getAuditNum());// 督办回复确认量
        dayLog.setErrNum(wtCheckDaylog.getAuditNum()); // 下发的工作底稿和风险记录表量
        dayLog.setWorkDesc1(wtCheckDaylog.getWorkDesc1());
        dayLog.setWorkDesc2(wtCheckDaylog.getWorkDesc2());
        dayLog.setWorkDesc6(wtCheckDaylog.getWorkDesc6());
        dayLog.setWorkDesc8(wtCheckDaylog.getWorkDesc8());
        dayLog.setCreateDate(DateTimeUtil.getDateFormat());//提交时间
        return wtCheckDaylogMapper.updateWtCheckDaylog(dayLog);

    }
    @Override
    public boolean addSave(WtCheckDaylog wtCheckDaylog) {
        String creator = wtCheckDaylog.getCreateOper();
        Date workDate =  wtCheckDaylog.getWorkDate();
        WtCheckDaylog daylog = wtCheckDaylogMapper.selectOne(new QueryWrapper<WtCheckDaylog>().eq("create_oper",creator).eq("work_date",workDate));
        if(daylog!=null){
            return false;
        }
        wtCheckDaylog.setAuditStatus(new Integer(0));
        wtCheckDaylog.setCreateDate(DateTimeUtil.getDateFormat());//提交时间
        String dayLogCode=this.getNewDayLogCode(workDate, creator);
        wtCheckDaylog.setCode(dayLogCode);
        wtCheckDaylogMapper.insert(wtCheckDaylog);
        return true;
    }
    @Override
    public String doCheckDayLogExists() {
        Date workDate = DateTimeUtil.getDateFormat();
        String creator = ShiroUtils.getSysUser().getLoginName();
        WtCheckDaylog daylog = wtCheckDaylogMapper.selectOne(new QueryWrapper<WtCheckDaylog>().eq("create_oper",creator).eq("work_date",workDate));
        if(daylog!=null){
            return daylog.getId();
        }
        return "false";
    }

    @Override
    public String doDateStatistics(WtCheckDaylogQuery wtCheckDaylog) {
        String reStr = "";
        //监控量
        int impAudit6 = 0;

        //处理风险量
        int dealError = 0;
        int randomAuditNum=0;
        int reAuditNum=0;
        int riskNum=0;
        int manualAuditNum=0;
        QueryWrapper queryWrapper = new QueryWrapper<PaeaReportBusiness>();
        queryWrapper.eq("operate_date",wtCheckDaylog.getWorkDate());
        queryWrapper.eq("operator",wtCheckDaylog.getCreateOper());
        List<PaeaReportBusiness> list = paeaReportBusinessMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            impAudit6 = list.get(0).getAuditNum();
            dealError= list.get(0).getDealErrorNum();
            //随机抽查
            randomAuditNum=list.get(0).getRandomAuditNum();
            //质量检查
            reAuditNum=list.get(0).getReAuditNum();
            //集中预警
            riskNum=list.get(0).getRiskNum()==null?0:list.get(0).getRiskNum();
            //人工选择监督
            manualAuditNum=list.get(0).getManualAuditNum();
        }
        // 重点监控量统计
        reStr = "@@" + impAudit6;
        //风险处理统计
        reStr += "@@" + dealError;
        // ARMS核销量
        /*中行无此需求，暂时注释*/
			/*int ARMSnum = serviceWtCheckDaylogImpl.statisticsARMS(workDate,
					noter);
			reStr += "@@" + ARMSnum;*/
        // 风险预警核实量
        int ocrNum = wtCheckDaylogMapper.statisticsRisk(wtCheckDaylog);
        reStr += "@@" + ocrNum;
        // 重点监控督办量
        int auditNum = wtCheckDaylogMapper.statisticsAudit(wtCheckDaylog);
        reStr += "@@" + auditNum;
        // 下发的工作底稿和风险记录表量
        int paperNum = 0;//wtCheckDaylogMapper.statisticsWorkPaper(wtCheckDaylog);
        reStr += "@@" + paperNum;
        //查看监控的机构
        String orgIdStr = this.queryPaeaAuBatchs4OrgId(wtCheckDaylog);
        String audtOrgId = StringUtils.isEmpty(orgIdStr)?ShiroUtils.getSysUser().getDeptId()+"^&^":orgIdStr;
        reStr += "@@" + audtOrgId;
        reStr += "@@" + randomAuditNum;
        reStr += "@@" + reAuditNum;
        reStr += "@@" + riskNum;
        reStr += "@@" + manualAuditNum;
        return  reStr;
    }

    @Override
    public List<PaeaAuBatch> queryPaeaAuBatchs4View(WtCheckDaylog wtCheckDaylog) {
        String yyyyMM = DateUtils.parseDateToStr("yyyyMM",wtCheckDaylog.getWorkDate());
        String yyyyMM_1 = "";
        int yearInt = Integer.parseInt(yyyyMM.substring(0, 4));
        int monthInt = Integer.parseInt(yyyyMM.substring(4, 6));
        if ("01".equals(yyyyMM.substring(4, 6))) {
            yearInt = yearInt - 1;
            yyyyMM_1 = yearInt + "12";
        } else {
            monthInt = monthInt - 1;
            if (monthInt < 10) {
                yyyyMM_1 = yyyyMM.substring(0, 4) + "0" + monthInt;
            } else {
                yyyyMM_1 = yyyyMM.substring(0, 4) + monthInt;
            }
        }
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        return wtCheckDaylogMapper.queryPaeaAuBatchs4View(createOper,workDate,yyyyMM,yyyyMM_1);
    }
    @Override
    public List<PaeaAuBatch> queryRandomPaeaAuBatchs4View(WtCheckDaylog wtCheckDaylog) {
        String yyyyMM = DateUtils.parseDateToStr("yyyyMM",wtCheckDaylog.getWorkDate());
        String yyyyMM_1 = "";
        int yearInt = Integer.parseInt(yyyyMM.substring(0, 4));
        int monthInt = Integer.parseInt(yyyyMM.substring(4, 6));
        if ("01".equals(yyyyMM.substring(4, 6))) {
            yearInt = yearInt - 1;
            yyyyMM_1 = yearInt + "12";
        } else {
            monthInt = monthInt - 1;
            if (monthInt < 10) {
                yyyyMM_1 = yyyyMM.substring(0, 4) + "0" + monthInt;
            } else {
                yyyyMM_1 = yyyyMM.substring(0, 4) + monthInt;
            }
        }
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        return wtCheckDaylogMapper.queryRandomPaeaAuBatchs4View(createOper,workDate,yyyyMM,yyyyMM_1);
    }
    @Override
    public List<PaeaAuBatch> queryManPaeaAuBatchs4View(WtCheckDaylog wtCheckDaylog) {
        String yyyyMM = DateUtils.parseDateToStr("yyyyMM",wtCheckDaylog.getWorkDate());
        String yyyyMM_1 = "";
        int yearInt = Integer.parseInt(yyyyMM.substring(0, 4));
        int monthInt = Integer.parseInt(yyyyMM.substring(4, 6));
        if ("01".equals(yyyyMM.substring(4, 6))) {
            yearInt = yearInt - 1;
            yyyyMM_1 = yearInt + "12";
        } else {
            monthInt = monthInt - 1;
            if (monthInt < 10) {
                yyyyMM_1 = yyyyMM.substring(0, 4) + "0" + monthInt;
            } else {
                yyyyMM_1 = yyyyMM.substring(0, 4) + monthInt;
            }
        }
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        return wtCheckDaylogMapper.queryManPaeaAuBatchs4View(createOper,workDate,yyyyMM,yyyyMM_1);
    }
    @Override
    public List<PaeaAuBatch> queryRePaeaAuBatchs4View(WtCheckDaylog wtCheckDaylog) {
        String yyyyMM = DateUtils.parseDateToStr("yyyyMM",wtCheckDaylog.getWorkDate());
        String yyyyMM_1 = "";
        int yearInt = Integer.parseInt(yyyyMM.substring(0, 4));
        int monthInt = Integer.parseInt(yyyyMM.substring(4, 6));
        if ("01".equals(yyyyMM.substring(4, 6))) {
            yearInt = yearInt - 1;
            yyyyMM_1 = yearInt + "12";
        } else {
            monthInt = monthInt - 1;
            if (monthInt < 10) {
                yyyyMM_1 = yyyyMM.substring(0, 4) + "0" + monthInt;
            } else {
                yyyyMM_1 = yyyyMM.substring(0, 4) + monthInt;
            }
        }
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        return wtCheckDaylogMapper.queryRePaeaAuBatchs4View(createOper,workDate,yyyyMM,yyyyMM_1);
    }
    @Override
    public List<PaeaErError> queryRegistErrView(WtCheckDaylog wtCheckDaylog) {
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        return wtCheckDaylogMapper.queryRegistErrView(createOper,workDate);
    }

    @Override
    public List<PaeaErError> queryDealErrView(WtCheckDaylog wtCheckDaylog) {
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        String yearStr = workDate.substring(0,4);
        return wtCheckDaylogMapper.queryDealErrView(createOper,workDate,yearStr);
    }
    @Override
    public List<PaeaErError> queryRiskErrView(WtCheckDaylog wtCheckDaylog) {
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = DateUtils.parseDateToStr("yyyy-MM-dd",wtCheckDaylog.getWorkDate());
        String yearStr = workDate.substring(0,4);
        return wtCheckDaylogMapper.queryRiskErrView(createOper,workDate,yearStr);
    }
    public String queryPaeaAuBatchs4OrgId(WtCheckDaylogQuery wtCheckDaylog) {
        /**
         * 组织查询条件
         */
        String createOper = wtCheckDaylog.getCreateOper();
        String workDate = wtCheckDaylog.getWorkDateStr();

        String yyyyMM = workDate.substring(0,7).replace("-","");
        String yyyyMM_1 = "";
        int yearInt = Integer.parseInt(yyyyMM.substring(0, 4));
        int monthInt = Integer.parseInt(yyyyMM.substring(4, 6));
        if ("01".equals(yyyyMM.substring(4, 6))) {
            yearInt = yearInt - 1;
            yyyyMM_1 = yearInt + "12";
        } else {
            monthInt = monthInt - 1;
            if (monthInt < 10) {
                yyyyMM_1 = yyyyMM.substring(0, 4) + "0" + monthInt;
            } else {
                yyyyMM_1 = yyyyMM.substring(0, 4) + monthInt;
            }
        }
        String orgIdStr = "";
        List<PaeaAuBatch>  paeaAuBatchList = wtCheckDaylogMapper.queryPaeaAuBatchs4View(createOper,workDate,yyyyMM,yyyyMM_1);
        for (PaeaAuBatch paeaAuBatch:paeaAuBatchList) {

            orgIdStr += paeaAuBatch.getOrgId() + "^&^";

        }
        return orgIdStr;
    }
    @Override
    public AjaxResult download(WtCheckDaylog wtCheckDaylog) {
        if (StringUtils.isEmpty(wtCheckDaylog.getId())){
            return AjaxResult.error("获取监督日志失败");
        }
        WtCheckDaylog daylog = wtCheckDaylogMapper.selectById(wtCheckDaylog.getId());
        if (daylog==null){
            return AjaxResult.error("获取监督日志失败");
        }
        String html = "<html>\n" +
                "\t<head>\n" +
                "\t\t<title>监控日志</title>\n" +
                "\t\t<style type=\"text/css\">\n" +
                ".STYLE1 {\n" +
                "\tfont-size: 18px;\n" +
                "\tfont-weight: bold;\n" +
                "}\n" +
                "\n" +
                ".STYLE2 {\n" +
                "\tfont-size: 12px;\n" +
                "\tfont-weight: bold;\n" +
                "}\n" +
                "\n" +
                ".STYLE3 {\n" +
                "\tfont-size: 12px;\n" +
                "}\n" +
                "</style>\n" +
                "\t</head>\n"+
                "\t<body>\n" +
                "\t\t<table width=\"550\" height=\"183\" border=\"1\" align=\"center\">\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td colspan=\"3\" align=\"center\">\n" +
                "\t\t\t\t\t<h3 class=\"STYLE1\">\n" +
                "\t\t\t\t\t\t中国银行辽宁省分行日常监控日志\n" +
                "\t\t\t\t\t</h3>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr align=\"left\">\n" +
                "\t\t\t\t<td width=\"23%\">\n" +
                "\t\t\t\t\t<span class=\"STYLE2\">日期</span>：\n" +
                "\t\t\t\t\t<span class=\"STYLE3\"> "+ DateTimeUtil.shortFmt(daylog.getWorkDate(),DateTimeUtil.FMT_YY_MM_DD)+"\n" +
                "\t\t\t\t\t</span>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td width=\"23%\" align=\"left\">\n" +
                "\n" +
                "\t\t\t\t\t<span class=\"STYLE2\">记录人：</span>\n" +
                "\t\t\t\t\t<span class=\"STYLE3\"> "+daylog.getCreateOper()+"\n" +
                "\t\t\t\t\t</span>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td width=\"*\" align=\"left\">\n" +
                "\n" +
                "\t\t\t\t\t<span class=\"STYLE2\">所在机构：</span>\n" +
                "\t\t\t\t\t<span class=\"STYLE3\"> "+daylog.getBrCode()+"\n" +
                "\t\t\t\t\t</span>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td colspan=\"3\">\n" +
                "\t\t\t\t\t<div align=\"center\" class=\"STYLE2\">\n" +
                "\t\t\t\t\t\t日结管理\n" +
                "\t\t\t\t\t</div>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t监控预警量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getAuditNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td  class=\"STYLE2\">\n" +
                "\t\t\t\t\t<!--<div align=\"right\">被监控机构、柜员信息：</div>\n" +
                "\t\t\t\t\t\t-->\n" +
                "\t\t\t\t\t\t<div align=\"right\">被监控机构信息：</div>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td  class=\"x-form-text\" colspan=\"2\">\n" +
                "\t\t\t\t\t<div id=\"divWORK_DESC8\" align=\"left\">"+(daylog.getWorkDesc8()==null?"":daylog.getWorkDesc8())+"</div>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\n" +
                "\t\t\t\n" +
                "\t\t\t\n" +
                "\t\t\t\n" +
                "\t\t\t<!--\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\tARMS预警核销量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getArmsNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\tOCR督办量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getOcrNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t-->\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t监控下发督办量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getRestoreNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t处理督办量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getErrNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t随机抽查量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getRandomauditNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t人工选择监督量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getManuauditNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t\t质量检查量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getReauditNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\t<td align=\"right\" class=\"STYLE2\">\n" +
                "\n" +
                "\t\t\t\t集中预警量：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" align=\"center\">\n" +
                "\t\t\t\t\t"+daylog.getRiskNum()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td colspan=\"3\" align=\"center\">\n" +
                "\t\t\t\t\t<div align=\"center\" class=\"STYLE2\">\n" +
                "\t\t\t\t\t\t工作情况\n" +
                "\t\t\t\t\t</div>\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td class=\"STYLE2\">\n" +
                "\t\t\t\t\t情况反馈：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" class=\"STYLE3\">\n" +
                "\t\t\t\t\t"+daylog.getWorkDesc1()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t\t<tr>\n" +
                "\t\t\t\t<td class=\"STYLE2\">\n" +
                "\t\t\t\t\t审核意见：\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t\t<td colspan=\"2\" class=\"STYLE3\">\n" +
                "\t\t\t\t\t"+daylog.getWorkDesc2()+"\n" +
                "\t\t\t\t</td>\n" +
                "\t\t\t</tr>\n" +
                "\t\t</table>\n" +
                "\t</body>\n" +
                "</html>";
        HtmlToWord htw = new HtmlToWord();
        return htw.writeWordFile(html,"d:/","日常监控日志");
    }

    /*modify
     * 根据具体要求将风险编号重新修改
     * 修改为：5位机构号+“-”+2位年号+“-”+3位顺序号
     * 排除预警项的编号
     * by pinghua.huang
     *
     */
    private String getNewDayLogCode(Date trDate, String creator) {
        String prefix = "";
        prefix =creator + "-"+ DateTimeUtil.dateFmt(trDate).substring(2,4) + "-";
        String year = DateTimeUtil.dateFmt(trDate).substring(0,4);
        String code = wtCheckDaylogMapper.selectMaxCode(year,creator);
        if (StringUtils.isEmpty(code)) {
            return prefix + "001";
        }
        String maxCode = StringUtils.isEmpty(code) ? "0" : code;
        if (maxCode.indexOf(prefix) == 0) {
            maxCode = maxCode.substring(prefix.length());
        }
        int seqNo = Integer.valueOf(maxCode.length() > 3 ? maxCode
                .substring(maxCode.length() - 3) : maxCode);
        if (seqNo > 999) {
            seqNo = 1;
        }
        return prefix + String.format("%03d", seqNo + 1);
    }

}
